<?php
session_start();
include('database.php');
include('functions.php');
include("language.php"); 

$_SESSION['curPage'] = 'home.php';

$query = $db->query("SELECT UNIX_TIMESTAMP(date) as timestamp, amount FROM draw WHERE status=1");

$data = $query->fetch();

$_SESSION['currentTime'] = time();
$_SESSION['drawCountDown'] = $data['timestamp'];
$_SESSION['amount'] = $data['amount'];
?>

<!DOCTYPE html>
<html>
    <head>
        <title><?php echo $home_home; ?></title>
        <meta charset="utf-8" />
        <meta property="og:url" content="www.d3lottery.com/" />
        <meta property="og:site_name" content="d3lottery.com" />
        <link rel="stylesheet" href="style.css" />
        <!-- Piwik --> 
            <script type="text/javascript">
            var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.t0m-s.be/" : "http://piwik.t0m-s.be/");
            document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
            </script>
            <script type="text/javascript">
                try {
                var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 13);
                piwikTracker.trackPageView();
                piwikTracker.enableLinkTracking();
            } catch( err ) {}
            </script>
            
            <!--<noscript><p><img src="http://piwik.t0m-s.be/piwik.php?idsite=13" style="border:0" alt="" /></p></noscript>-->
        <!-- End Piwik Tracking Code -->
    </head>
    <body onLoad="CountDown();">
        <div class="d_body">

            <?php include('header.php'); ?>
            <?php include("menuBar.php"); ?>
            <?php include("myAccount.php"); ?>
            
            <script>
                var currentDate = new Date(<?php echo $_SESSION['currentTime'] * 1000; ?>);
                function CountDown()
                {
                    currentDate.setTime(currentDate.getTime() + 1000);
                    var drawDate = new Date(<?php echo $_SESSION['drawCountDown'] * 1000; ?>);
                    
                   
                    var timeLeft = drawDate.getTime() - currentDate.getTime();


                    var sec = timeLeft / 1000; 
                    var min = sec / 60;
                    var hour = min / 60;
                    var day = hour / 24;


                    sec = Math.floor(sec % 60); 
                    min = Math.floor(min % 60);
                    hour = Math.floor(hour % 24); 
                    day = Math.floor(day); 

                    document.getElementById("countDown").innerHTML = "<?php echo $home_playAndWin2; ?>" + day + " <?php echo $home_day ?> " + hour + " <?php echo $home_hour; ?> " + min + " <?php echo $home_minute; ?> " + sec + " <?php echo $home_second; ?> "
                }
                setInterval(CountDown, 1000);
                    
            </script>            

            <section class="main_section">
                <br>
                <!--<p class="winner">
                    <?php /*echo $home_winner;*/ ?>
                </p>-->
                    <table class="homeCenter">
                        <?php
                        echo '<tr><td>' . $home_thx . '</td></tr>';
                        echo '<tr><td><br></td></tr>';
                        echo '<tr><td>OLIIVE#2841, ';
                        echo 'SCHNORZEL#1203, ';
                        echo 'KOUDBOUL#1237, ';
                        echo 'SEITH#2365 and';
                        echo 'SCRATCH#2961</td></tr>';
                        echo '<tr><td><br></td></tr>';
                        echo '<tr><td><br></td></tr>';
                        echo '<tr><td>- ' . $home_thx2 . ' -</td></tr>';
                        echo '<tr><td><br></td></tr>';
                        echo '<tr><td><br></td></tr>';
                        /*
                        if($query->rowCount() > 0)
                        {
                            if($_SESSION['drawCountDown'] > $_SESSION['currentTime'])
                            {

                                echo '<tr>';
                                echo '    <td class="cellTextCenter"><div class="small">' . $home_europe . '</div></td>';
                                echo '</tr>';
                                
                                echo '<tr>';
                                echo '    <td class="cellTextCenter"><strong class="big">' . $home_playAndWin1 . ' ' . parseAmount($_SESSION['amount']) . $draws_gold . '</strong></td>';
                                echo '</tr>';

                                echo '<tr>';
                                echo '    <td id="countDown" class="cellTextCenter"></td>';
                                echo '</tr>';

                            }
                            else 
                            {

                                echo '<tr>';
                                echo '    <td class="cellTextCenter"><strong>' . $home_participationClosed . '</strong></td>';
                                echo '</tr>';
                                
                                echo '<tr>';
                                echo '    <td class="cellTextCenter"><a href="webTv.php">' . $home_drawingLive . '</a></td>';
                                echo '</tr>';
                            }
                        }*/
                        ?>
                    </table>

                <?php
                /*
                <div class="d_slog">
                    <ul>
                        <li><?php echo $home_firstParticipationFree; ?></li>
                        <li><?php echo $home_label1; ?></li>
                        <li><?php echo $home_label2; ?></li>
                        <li><?php echo $home_label3; ?></li>
                        <li><?php echo $home_label4; ?></li>
                    </ul>
                </div>
                
                <table class="homeCenter">
                    <tr><td>
                        <?php 
                            if(isset($_SESSION['connected']) AND $_SESSION['connected'])
                            {
                                echo '<form method="post" action="draws.php">';
                                echo '<input class="large" type="submit" value="' . $home_participate . '" />';
                                
                            }
                            else 
                            {
                                echo '<form method="post" action="register.php">';
                                echo '<input class="large" type="submit" value="' . $home_registerNow . '" />';
                            }
                        ?>
                        </form>
                    </td></tr>
                </table>*/
                ?>
                <?php
                        $query = $db->query("SELECT username FROM user ORDER BY registrationDate DESC LIMIT 0, 20");

                        echo '<p>' . $home_lastSubscribers;
                        $i = 0;
                        while($data = $query->fetch())
                        {
                            if($i != 0)
                            {
                                echo ', ';
                            }
                            
                            echo $data['username'];
                            $i++;
                        }
                        echo '</p>';

                        $query->closeCursor();
                ?>
                
                <p class="partners">
                    <?php echo $home_partners; ?>
                </p>
            </section>
        </div>
        <?php include('footer.php'); ?>
    </body>
</html>
